package com.training.java.core.collections.post15;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * Map maintains Key Value pair HashMap is the simple form of map
 * 
 * @author soumya
 * 
 */
public class SchoolMapDemo {

	public static void main(String[] args) {

		Map<String, String> students = new HashMap<String, String>();

		// adding students and school
		students.put("Tracy", "Ruskin");
		students.put("John", "Cherrywood");
		students.put("Sarah", "Curtner");

		// adding duplicate..overrides the old value
		students.put("Sarah", "Ruskin");

		// reading the School name for a particular student

		String school = students.get("Sarah");
		System.out.println("Sarah's School is " + school);
		System.out.println("  ");

		// to read all the key - values

		Set<Entry<String, String>> entries = students.entrySet();

		for (Entry<String, String> entry : entries) {
			System.out.println("Key = " + entry.getKey());
			System.out.println("Value = " + entry.getValue());

		}

	}

}
